/*****************************************************************************************
 * FILE NAME: app_soc                       COPYRIGHT (c) cos 2024
 * REVISION:  1.0.0                                     All Rights Reserved
 * DESCRIPTION:
 * =======================================================================================
 * UPDATE HISTORY:
 * REV      AUTHOR      DATE
 * v1.0.0   Tuxin       2024.10.14
 * DESCRIPTION OF CHANGE:
 ****************************************************************************************/
#ifndef __APP_SOC_H
#define __APP_SOC_H

//----------------------------------------------------------------------------------------
// @Project Includes
#include "typedefs.h"

//----------------------------------------------------------------------------------------
// @Global Macro Define in the module
#define TEMP_CA_TABLE_LEN   								(10)

#define SOC_PACKFULLY_VLUE_LFP          		(3600)/*mV*/
#define SOC_PACKEMPTY_VLUE_LFP          		(2500)/*mV*/
#define SOC_PACKFULLY_VLUE_NCM          		(4150)/*mV*/
#define SOC_PACKEMPTY_VLUE_NCM           		(2800)/*mV*/

#define T_Rest_th                 		    	(1*3600)
#define COULOMB_EFF_CHARGE        	        (1.0000f)
#define COULOMB_EFF_DISCHARGE     	        (1.0000f)
#define BALANCED_RESISTANCE       	        (20)
#define T_Simple                  					(500)
#define T_SOC_RUN                 					(1000/T_Simple)
#define SOC_COEFFICIENT        		        	(1000000)
#define SOC_COEFFICIENT_DISABLE_REFRESH     (980000)
#define SOC_COEFFICIENT_ENABLE_JUMP   			(900000)
#define SOC_COEFFICIENT_DISABLE_MIN_REFRESH (19999)
#define SOC_COEFFICIENT_ENABLE_MIN_JUMP     (19999)

#define CAP_COEFFICIENT           		    	(10000)
#define SOC_COEFFICIENT_OFFSET      	    	(5000)
#define SOC_MAX_CYCLE_NUM     	    				(1000)
#define SOC_MAX_CYCLE_LOSS    	    				(2000)

//----------------------------------------------------------------------------------------
// @Global Type defines in the module
typedef enum en_soc_overflowflag
{
    CELL_SOC_NORMAL               			= 0,
    CELL_SOC_OVER_TOP             			= 1,
    CELL_SOC_TOO_LOW              			= 2,
}en_soc_overflowflag_t;

typedef enum en_soc_packstate
{
    SOC_PACK_CHARGE_STATE         			= 1,
    SOC_PACK_DISCHARGE_STATE      			= 2,
}en_soc_packstate_t;

typedef struct stc_soc_data
{
    uint32_t u32displayValue;
    uint32_t u32trueValue;
    int32_t  i32cellValue[BMS_MAX_CELLNUM];
    uint8_t  u8maxChnNum;
    uint8_t  u8minChnNum;
}stc_soc_data_t;

typedef enum en_soc_state
{
    SOC_STATE_IDLE 				= 0,
    SOC_STATE_INITWAIT		= 1,
    SOC_STATE_INIT  			= 2,
    SOC_STATE_ARITHMETIC 	= 3,
}en_soc_state_t;

typedef struct stc_soc
{
		uint8_t SOH;
	  uint32_t u32tempCaTableMaxCap[TEMP_CA_TABLE_LEN];
    bool_t bdemarcate;
    stc_soc_data_t stcdata;
    en_soc_state_t enState;	
    int32_t i32socMax;
    int32_t i32socMin;

    uint32_t u32chgRemainTime;
    uint32_t u32dsgRemainTime;
    uint32_t u32cycleCapCount;
    uint32_t u32fullChgCapCount;
    bool_t bfullChgCapAutoLearnFlag;

    en_soc_packstate_t enSocPackState;
    bool_t SOC_Enable;
    float_t W_Display;
    float_t W1;
    float_t W2;
    int32_t b;
    bool_t PackFullyCharge;
    uint8_t SOCRunCount;
    bool_t ChargeWeightFlag;
    bool_t DischargeWeightFlag; 
    uint32_t SOC_Deal;
		
}stc_soc_t;

//----------------------------------------------------------------------------------------
// @Export global Variables declare in the module
extern volatile stc_soc_t g_stcSoc;

//----------------------------------------------------------------------------------------
// @Export declaration of functions in the module
void app_soc_init(void);
void app_soc_setPackFull(bool_t enable);
void app_soc_task(void);

#endif

// =======================================================================================
// End of file.
// =======================================================================================
